package ro.upt.ac.cstaicu.execution;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

public class CachedClassFilesManager {

	private static HashMap<String, File> history = new HashMap<String, File>();
	
	public synchronized static CachedClassFileResult getClass(String name) throws IOException {
		if (history.containsKey(name)) {
			return new CachedClassFileResult(history.get(name), true);
		} else {
			File tempFile = File.createTempFile(name.replace(".", ""), "class");
			tempFile.deleteOnExit();
			history.put(name, tempFile);
			return new CachedClassFileResult(tempFile, false);
		}
	}

	public static void clearHistory() {
//		history.clear();
		history = new HashMap<String, File>();
	}	
	
	
}
